package com.sh.stream流;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class StreamDemo6 {
    public static void main(String[] args) {
        ArrayList<String> nameList = new ArrayList<>();
        Collections.addAll(nameList, "张无忌", "张三", "李四", "王五", "赵六", "赵六", "赵六", "赵六");
        ArrayList<String> nameList2 = new ArrayList<>();
        Collections.addAll(nameList2, "张无忌", "张三", "周芷若", "孙悟空", "猪八戒");

//        nameList.stream().filter(name->name.startsWith("张")).forEach(System.out::println);

//        nameList.stream().skip(3).forEach(System.out::println);  // 跳过3个
//        nameList.stream().limit(3).forEach(System.out::println);  // 前3个

//        nameList.stream().distinct().forEach(System.out::println);

        // 合并
//        Stream.concat(nameList.stream(), nameList2.stream()).forEach(System.out::println);
        // ***map方法***
        ArrayList<String> nameList3 = new ArrayList<>();
        Collections.addAll(nameList3, "张无忌-11", "张三-22", "周芷若-33", "孙悟空-44", "猪八戒-55");
//        nameList3.stream().map(new Function<String, Integer>() {
//            @Override
//            public Integer apply(String s) {
//                int i = s.indexOf("-");
//                String substring = s.substring(i + 1, s.length());
//                Integer i1 = Integer.valueOf(substring);
//                return i1;
//            }
//        }).forEach(System.out::println);
        nameList3.stream()
                .map(s -> Integer.valueOf(s.split("-")[1]))
                .forEach(System.out::println);
    }
}

